package game.map.mapEvents;

import processing.core.PApplet;
import game.map.Static;
import game.map.WsApplet;
import game.mapEditor.WsAppletMapEditor;

abstract public class MapEvent {
	
	private String eventId;
	private int x, y;
	private int fx, fy;
	
	public MapEvent(String eventId, int x, int y, int fx, int fy) {
		this.eventId = eventId;
		this.x = x;
		this.y = y;
		this.setFx(fx);
		this.setFy(fy);
	}
	
	public MapEvent(String[] encoded) {
		this(encoded[1], Integer.parseInt(encoded[2]), Integer.parseInt(encoded[3]), 
				Integer.parseInt(encoded[4]), Integer.parseInt(encoded[5]));
	}
	
	public String getEventId() {
		return eventId;
	}
	public void setEventId(String eventId) {
		this.eventId = eventId;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}

//	public void drawIndicator(WsAppletMapEditor app, int side) {
//		app.fill(Static.GRAY);
//		app.noStroke();
//		app.ellipse(x*side + side/2, y*side + side/2, 15, 15);
//	}
//	
//	abstract public String toString(String sep);

	public int getFx() {
		return fx;
	}

	public void setFx(int fx) {
		this.fx = fx;
	}

	public int getFy() {
		return fy;
	}

	public void setFy(int fy) {
		this.fy = fy;
	}
	
	public void setBounds(int fx, int fy) {
		setFx(fx);
		setFy(fy);
	}
	
	public boolean inArea(int x, int y) {
		return getX() <= x && getY() <= y && getFx() >= x && getFy() >= y;
	}

	public void drawIndicator(PApplet app, int side) {
		
		app.fill(getColor() - Static.transp);
		app.strokeWeight(1);
		app.stroke(Static.GRAY);
		app.rect(getX() * side + side/3,
				getY() * side + side/3, 
				(getFx() - getX()) * side + side/3, 
				(getFy() - getY()) * side + side/3);
//		System.out.println(getX() + " " + getY() + " " + fx + " " + fy);
	}
	
	abstract protected int getColor();

	public String encode(String sep) {
		return "event " + getEventId() + sep + getX() + sep 
				+ getY() + sep + getFx() + sep + getFy();
	}

}
